import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAppStore = defineStore('app', () => {
  // 状态
  const loading = ref<boolean>(false)
  const theme = ref<'light' | 'dark'>('light')
  const sidebarCollapsed = ref<boolean>(false)
  const language = ref<'zh-CN' | 'en-US'>('zh-CN')

  // 方法
  const setLoading = (status: boolean) => {
    loading.value = status
  }

  const toggleTheme = () => {
    theme.value = theme.value === 'light' ? 'dark' : 'light'
  }

  const toggleSidebar = () => {
    sidebarCollapsed.value = !sidebarCollapsed.value
  }

  const setLanguage = (lang: 'zh-CN' | 'en-US') => {
    language.value = lang
  }

  return {
    // 状态
    loading,
    theme,
    sidebarCollapsed,
    language,
    // 方法
    setLoading,
    toggleTheme,
    toggleSidebar,
    setLanguage
  }
})
